package demo3;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-06
 * Time: 16:59
 */
public class Test {         //简单的洗牌算法
    public static final String[] SUIT = {"♠","♣","♦","♥"};
    public static List<Card> buyCard(){
        List<Card> list = new ArrayList<>();
        for (int i = 0; i < SUIT.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(SUIT[i], j);
                list.add(card);
            }
        }
        return list;
    }

    public static void shuffle(List<Card> cards){
        Random random = new Random();
        for (int i = cards.size() - 1; i > 0 ; i--) {
            int j = random.nextInt(i);
            Card temp = cards.get(i);
            cards.set(i, cards.get(j));
            cards.set(j, temp);
        }
    }

    public static void playCards(){
        List<Card> cards = buyCard();

        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hand = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                hand.get(j).add(card);
            }
        }
        System.out.println("A摸到的牌: ");
        System.out.println(hand1);
        System.out.println("B摸到的牌: ");
        System.out.println(hand2);
        System.out.println("C摸到的牌: ");
        System.out.println(hand3);

        System.out.println("还剩余 " + cards.size() + " 张扑克牌");
        System.out.println(cards);
    }

/*    public static void remainCards(){
        List<Card> cards = buyCard();
        System.out.println("剩余的扑克牌: ");
        System.out.println(cards);
    }*/
    public static void main(String[] args) {
        List<Card> cards = buyCard();

        System.out.println("一共 " + cards.size() + " 张扑克牌");
        System.out.println(cards);
        System.out.println("洗牌后：");
        shuffle(cards);
        System.out.println(cards);

        playCards();

    }
}